import socket, threading

def tcp_to_udp(tcp_port, udp_host, udp_port):
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind(('0.0.0.0', tcp_port))
    server.listen(5)

    while True:
        client, addr = server.accept()
        udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        def forward():
            while True:
                data = client.recv(1024)
                if not data: break
                udp_sock.sendto(data, (udp_host, udp_port))
            client.close()

        threading.Thread(target=forward).start()

# 启动转发器
tcp_to_udp(47998, '目标IP', 48000)
tcp_to_udp(48010, '目标IP', 48010)